package com.test.resumeanalysis.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.test.resumeanalysis.data.model.JobPost
import com.test.resumeanalysis.data.model.resume.ResumeParse

@Database(
    entities = [ResumeParse::class,JobPost::class],
    version = 3,
    exportSchema = true,
)
@TypeConverters(Converter::class)
abstract class DataBase : RoomDatabase() {

    abstract fun resumeDao(): ResumeDao
    abstract fun jobPostDao():JobPostDao
    companion object {

//        val MIGATION_1_2 = object : Migration(1, 2) {
//            override fun migrate(database: SupportSQLiteDatabase) {
//                database.execSQL("alter table ToDoData add column ")
//            }
//        }

        @Volatile
        private var INSTANCE: DataBase? = null

        fun getDataBase(context: Context): DataBase {
            val tempInstance = INSTANCE
            if (tempInstance != null) {
                return tempInstance
            }

            synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    DataBase::class.java,
                    "resume_database"
                ).fallbackToDestructiveMigration().build()
                INSTANCE = instance
                return instance
            }
        }

    }
}